package com.crunch.core;

public class Actor {
	private Engine engine;
	public final Engine getEngine() {
		return engine;
	}

	private GameState gameState;
	public final GameState getGameState() {
		return gameState;
	}

	private boolean inUpdateQueue;
	public final boolean isInUpdateQueue() {
		return inUpdateQueue;
	}

	private int updatePriority;
	public final int getUpdatePriority() {
		return updatePriority;
	}

	private boolean doesExist;
	public final boolean exists() {
		return doesExist;
	}

	void setDoesNotExist() {
		doesExist = false;
	}

	// constructor for actors not in the update queue
	public Actor() {
		inUpdateQueue = false;
		doesExist = true;
	}

	// constructor for actors in the update queue
	public Actor(int updatePriority) {
		inUpdateQueue = true;
		doesExist = true;
		this.updatePriority = updatePriority;
	}

	// called by engine - don't call this manually
	final void initialize(GameState gameState) {
		engine = gameState.getEngine();
		this.gameState = gameState;
	}

	public final void destroy() {
		gameState.destroyActor(this);
	}

	// override these methods where necessary

	public void onCreate() {}   // called right after the game state is created
	public void onUpdate() {}   // called at each update
	public void onDestroy() {}  // called right before the game state is destroyed
}
